package Test1;

import java.util.Arrays;
import java.util.Scanner;

public class Test19 {
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()){
        int p = scanner.nextInt();
        int sum = 0;
        int max = 0;
        while (p != 0){
            if((p & 1) == 1){
                sum++;
            }
            p >>= 1;
        }
        System.out.println(sum);

    }
    }

    public static void main(String[] args) {
        int []array1 = {0,7,1,6};
        int []array2 = {1,5,0,6};
        System.out.println(findMinimum(4, array1, array2));
    }
    public  static int findMinimum(int n, int[] left, int[] right) {
        // write code here
        //记录0对应的值
        int sum = 0;
        //记录总手套
        int sum1 = 0;
        int sum2 = 0;
        //记录最小值
        int min1 = Integer.MAX_VALUE;
        int min2 = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {

            if(left[i] * right[i] == 0){
                sum += left[i]+right[i];
            }else {
                //求最小值
                if(min1 > left[i]){
                    min1 = left[i];
                }
                if(min2 > right[i]){
                    min2 = right[i];
                }
                sum1+=left[i];
                sum2+=right[i];
            }
        }

        return Math.min(sum1 - min1 + 1,sum2 + 1 - min2) + sum + 1;


    }
}
